package es.xpt.ysf.jaas.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import es.xpt.ysf.view.model.LocaleDescriptionBean;

public class PrivelegesGroupBean {

	private String id;
	private HashMap<String, LocaleDescriptionBean> descriptions = new HashMap<String, LocaleDescriptionBean>(1);
	private List<PrivelegesGroupBean> children = new ArrayList<PrivelegesGroupBean>();

	
	public class Action {
		private String className;
		private String methodName;

		/**
		 * @return the className
		 */
		public String getClassName() {
			return className;
		}

		/**
		 * @param className
		 *            the className to set
		 */
		public void setClassName(String className) {
			this.className = className;
		}

		/**
		 * @return the methodName
		 */
		public String getMethodName() {
			return methodName;
		}

		/**
		 * @param methodName
		 *            the methodName to set
		 */
		public void setMethodName(String methodName) {
			this.methodName = methodName;
		}

	}

	private ArrayList<Action> actions = new ArrayList<Action>();
	private boolean exclusive = false;
	private PrivelegesGroupBean parent;

	public PrivelegesGroupBean() {
		super();
	}

	public void addGroup(PrivelegesGroupBean group) {
		add(group);
	}

	/**
	 * @return the groups
	 */
	public List<PrivelegesGroupBean> getGroups() {
		return getChildren();
	}

	/**
	 * @param groups
	 *            the groups to set
	 */
	public void setGroups(List<PrivelegesGroupBean> groups) {
		setChildren(groups);
	}

	/**
	 * @return the parent
	 */
	public PrivelegesGroupBean getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setParent(PrivelegesGroupBean parent) {
		this.parent = parent;
	}

	/**
	 * @return the actions
	 */
	public ArrayList<Action> getActions() {
		return actions;
	}

	/**
	 * @param actions
	 *            the actions to set
	 */
	public void setActions(ArrayList<Action> actions) {
		this.actions = actions;
	}

	public void addAction(Action action) {
		actions.add(action);
	}

	public boolean isExclusive() {
		return exclusive;
	}

	public void setExclusive(boolean exclusive) {
		this.exclusive = exclusive;
	}
	
	public void addDescription(LocaleDescriptionBean description) {
		descriptions.put(description.getLocale().toLowerCase(), description);
	}
	
	private void add (PrivelegesGroupBean element) {
		children.add(element);
	}
	
	
	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
	public LocaleDescriptionBean getDescription(String locale) {
		return descriptions.get(locale.toLowerCase());
	}
	/**
	 * @return the descriptions
	 */
	public HashMap<String, LocaleDescriptionBean> getDescriptions() {
		return descriptions;
	}
	/**
	 * @param descriptions the descriptions to set
	 */
	public void setDescriptions(
			HashMap<String, LocaleDescriptionBean> descriptions) {
		this.descriptions = descriptions;
	}

	/**
	 * @return the children
	 */
	protected List<PrivelegesGroupBean> getChildren() {
		return children;
	}

	/**
	 * @param children the children to set
	 */
	protected void setChildren(List<PrivelegesGroupBean> children) {
		this.children = children;
	}

	

}
